<?php

/**
 * This is the model class for table "tbl_monyrec".
 *
 * The followings are the available columns in table 'tbl_monyrec':
 * @property integer $moID
 * @property integer $readerID
 * @property string $name
 * @property string $type
 * @property string $money
 *
 * The followings are the available model relations:
 * @property Users $name0
 * @property Reader $reader
 */
class Monyrec extends CActiveRecord
{
	/**
	 * 定义常量：
	 * 操作类型常量，
	 */
	const MONY_ADD='存入';
	const MONY_REDUSE='逾期使用费';
	const MONY_PRINT='打印复印';
	const MONY_SACN='扫描';
	const MONY_EDITORIAL_SRV='专题服务';
	
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Monyrec the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_monyrec';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('moID', 'required'),
			array('moID, readerID', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>10),
			array('type', 'length', 'max'=>20),
			array('money', 'length', 'max'=>8),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('moID, readerID, name, type, money', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'name0' => array(self::BELONGS_TO, 'Users', 'name'),
			'reader' => array(self::BELONGS_TO, 'Reader', 'readerID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'moID' => 'Mo',
			'readerID' => 'Reader',
			'name' => 'Name',
			'type' => 'Type',
			'money' => 'Money',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('moID',$this->moID);
		$criteria->compare('readerID',$this->readerID);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('money',$this->money,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}